<?php
class table_model extends MY_model
{
    public $id;
    public $name;
    public $order_by;

    public function get_elements()
    {
        $query = $this->db->query("SELECT * FROM tables ORDER BY order_by ASC");
        return $this->to_domain_models($query->result());
    }

    public function get_element_by_id($id)
    {
        $query = $this->db->query("SELECT * FROM tables WHERE id = ?",array($id));
        return $this->to_domain_model($query->row());
    }

    public function get_last_record()
    {
        $query = $this->db->query("SELECT * FROM tables ORDER BY order_by DESC LIMIT 1");
        return $this->to_domain_model($query->row());
    }
    // -------------------------------------------------------------------------------- PRIVATE PROPERTIES

    public function get_active()
    {
        $result = false;
        if($this->store_model->get_element_by_table($this->id)->id != '')
            $result = true;
        return $result;
    }

    // -------------------------------------------------------------------------------- PRIVATE METHOD

    // Private method
    public function to_domain_model($item)
    {
        $model = new table_model();
        $model->id = isset($item->id) ? $item->id : '' ;
        $model->name = isset($item->name) ? $item->name : '' ;
        $model->order_by = isset($item->order_by) ? $item->order_by : '' ;
        return $model;
    }
}